$(function () {
    let university = $('#university');
    let college = $('#college');
    let label = $('#label');

    $.ajax({
        method: "GET",
        url: '/universities',
        success: function (uni) {
            university.devbridgeAutocomplete({
                lookup: uni,
                onSelect: function (sug) {
                    label.show();
                    college.show();
                    $.ajax({
                        method: 'GET',
                        url: '/universities/' + sug.value.charAt(0) + '/colleges',
                        success: function (col) {
                            college.val('');
                            college.devbridgeAutocomplete({
                                lookup: col
                            })
                        }
                    })
                }
            })
        }
    });

    university.on('search', function () {
        label.hide();
        college.hide()
    })
});
